package com.example.my.meila.view.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.my.meila.R;
import com.example.my.meila.common.base.MyView;
import com.example.my.meila.common.image.ImageLoader;
import com.example.my.meila.entity.Login;
import com.example.my.meila.view.activity.LoginActivity;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * A simple {@link Fragment} subclass.
 */
public class MeFragment extends Fragment {


    @BindView(R.id.iv_me)
    MyView ivMe;
    @BindView(R.id.tv_login)
    TextView tvLogin;
    @BindView(R.id.tv_back)
    TextView tvback;
    @BindView(R.id.llll)
    LinearLayout llll;
    @BindView(R.id.llin)
    LinearLayout llin;
    @BindView(R.id.iv_denglu)
    ImageView ivDenglu;
    @BindView(R.id.tv_denglu)
    TextView tvDenglu;


    public MeFragment() {
        // Required empty public constructor
    }

    public static MeFragment newInstance() {

        Bundle args = new Bundle();

        MeFragment fragment = new MeFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_me, container, false);
        ButterKnife.bind(this, view);
        EventBus.getDefault().register(this);
        llin.setVisibility(View.INVISIBLE);

        return view;
    }

    @OnClick({R.id.iv_me, R.id.tv_login, R.id.tv_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_me:
                Intent intent = new Intent(getActivity(), LoginActivity.class);
                startActivity(intent);
                break;
            case R.id.tv_login:
                Intent intent2 = new Intent(getActivity(), LoginActivity.class);
                startActivity(intent2);
                break;
            case R.id.tv_back:
                llll.setVisibility(View.VISIBLE);
                llin.setVisibility(View.GONE);
                break;
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void test(String a) {
        if (a.equals("123")) {
            llll.setVisibility(View.GONE);
            llin.setVisibility(View.VISIBLE);
        }
    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void loginweibo(Login login) {
        ImageLoader.getInstance().transformationsImage(getContext(),login.getIcon(),ivDenglu);
        tvDenglu.setText(login.getName().toString());
        }
    }

